<?
include('../controller/handler.php');
include('../controller/philomousia.php');
include('../controller/calendar.php');

$hd = new Handler();
$ph = new Philomousia();
$cal = new Calendar();

$pivot = $_POST['timestamp'];

$calendar = $cal->generateCalendar(date("Y", $pivot), date("m", $pivot));
$base_url = $hd->getBaseURL();
$hd->openDB();
$days = $ph->getAllNotEmptyDays(date("Y", $pivot), date("m", $pivot), $hd);
$hd->closeDB();
?>

<p class="calendar_month">
	<?$script = 'onclick="updateCalendar(this.id, \''.$base_url.'\')"';?>
	<?$back = mktime(0, 0, 0, date("m", $pivot)-1, 1, date("Y", $pivot));?>
	<?$forth = mktime(0, 0, 0, date("m", $pivot)+1, 1, date("Y", $pivot));?>
	<span class="small month_nav pseudo_link" id="<?echo $back;?>" <?echo $script;?>>
		<?echo strftime("%b", $back);?>
	</span>
	<?echo strftime("%B %Y", $pivot);?>
	<span class="small month_nav pseudo_link" id="<?echo $forth;?>" <?echo $script;?>>
		<?echo strftime("%b", $forth);?>
	</span>
</p>
<table border="0" cellspacing="0" cellpadding="2">
<?foreach($calendar as $index => $row) {?>
	<tr>
	<?foreach($row as $day) {
		if($index==0){?>
		<td class="calendar_day"><?echo $day;?></td>
		<?} elseif(in_array($day, $days)) {?>
		<td class="bold"><a href="<?echo $base_url;?>archive/<?echo strftime("%Y", $pivot)?>:<?echo strftime("%m", $pivot)?>:<?echo $day?>"><?echo $day;?></a></td>
		<?} else {?>
		<td><?echo $day;?></td>
		<?}
	}?>
	<tr>
<?}?>
</table>